package com.aloda.mapper;

import com.aloda.pojo.dto.UserLoginDTO;
import com.aloda.pojo.dto.UserPageDTO;
import com.aloda.pojo.entity.User;
import com.github.pagehelper.Page;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Select;

@Mapper
public interface UserMapper {

    @Select("select * from user where user_email=#{email} AND user_password=#{password}")
    @Results(id = "userMap",value = {
            //id字段默认为false，表示不是主键
            //column表示数据库表字段，property表示实体类属性名。
            @Result(id = true,column = "user_id",property = "id"),
            @Result(column = "user_name",property = "name"),
            @Result(column = "user_password",property = "password"),
            @Result(column = "user_email",property = "email"),
            @Result(column = "user_hiredate",property = "hiredate"),
            @Result(column = "user_role",property = "role"),
            @Result(column = "user_status",property = "status"),
            @Result(column = "user_departuredate",property = "departuredate")
    })
    User SelectUserByUnAndPw(UserLoginDTO userLoginDTO);

    /**
     * 分页查询用户
     * @param userPageDTO
     * @return
     */
    Page<User> selectPage(UserPageDTO userPageDTO);

    /**
     * 根据用户名（邮箱）查找用户
     * @param email
     * @return
     */
    User selectUserByUn(String email);

    /**
     * 新增用户
     * @param user
     */
    void insert(User user);

    /**
     * 根据id查找用户
     * @param id
     * @return
     */
    User selectUserById(Integer id);

    /**
     * 更新用户信息
     * @param user
     */
    void update(User user);
}
